﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebPromenadebyenTabeller;
using System.Data.SqlClient;
using System.Configuration;

namespace PromViewPersonerDB
{
    public static class PromGatewayViewPersoner
    {

        const String CONNECTION_STRING = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PromDatabase.mdf;Integrated Security=True;User Instance=True";

        public static List<ViewPersoner> FindAlleViewPersoner()
        {
            List<ViewPersoner> nyListe = new List<ViewPersoner>();

            //SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
            con.ConnectionString = CONNECTION_STRING;

            con.Open();

            System.Data.IDbCommand command = con.CreateCommand();
            command.CommandText = "SELECT * FROM VIEWPERSONER";

            System.Data.IDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                int personID = int.Parse(reader["personID"].ToString());
                string navnperson = reader["navnPerson"].ToString();
                string adresse = reader["adresse"].ToString();
                int postnr = int.Parse(reader["postnr"].ToString());
                string by = reader["bynavn"].ToString();               

                int nummer = int.Parse(reader["nummer"].ToString());
                int sal = int.Parse(reader["sal"].ToString());
                string side = reader["side"].ToString();

                string navnByg = reader["navnByg"].ToString();

                ViewPersoner nyViewPerson = new ViewPersoner(personID,navnperson,adresse,postnr,by,nummer,sal,side,navnByg);

                nyListe.Add(nyViewPerson);

            }

            con.Close();
            return nyListe;
        }

  }
}
